package com.hjm.project.agentAysinfo.agentAysinfo.controller;

import com.hjm.common.utils.DateUtils;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.common.utils.security.ShiroUtils;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.agentAysinfo.agentAysinfo.domain.AgentAysinfo;
import com.hjm.project.agentAysinfo.agentAysinfo.service.IAgentAysinfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 代理商推送配置Controller
 * 
 * @author maker-platform
 * @date 2024-05-13
 */
@Controller
@RequestMapping("/agentAysinfo/agentAysinfo")
public class AgentAysinfoController extends BaseController {
    private String prefix = "agentAysinfo/agentAysinfo";

    @Resource
    private IAgentAysinfoService agentAysinfoService;

    @RequiresPermissions("agentAysinfo:agentAysinfo:view")
    @GetMapping()
    public String agentAysinfo() {
        return prefix + "/agentAysinfo";
    }

    /**
     * 查询代理商推送配置列表
     */
    @RequiresPermissions("agentAysinfo:agentAysinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentAysinfo agentAysinfo) {
        startPage();
        List<AgentAysinfo> list = agentAysinfoService.selectAgentAysinfoList(agentAysinfo);
        return getDataTable(list);
    }

    /**
     * 导出代理商推送配置列表
     */
    @RequiresPermissions("agentAysinfo:agentAysinfo:export")
    @Log(title = "代理商推送配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentAysinfo agentAysinfo) {
        List<AgentAysinfo> list = agentAysinfoService.selectAgentAysinfoList(agentAysinfo);
        ExcelUtil<AgentAysinfo> util = new ExcelUtil<AgentAysinfo>(AgentAysinfo.class);
        return util.exportExcel(list, "agentAysinfo");
    }

    /**
     * 新增代理商推送配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理商推送配置
     */
    @RequiresPermissions("agentAysinfo:agentAysinfo:add")
    @Log(title = "代理商推送配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentAysinfo agentAysinfo) {
        agentAysinfo.setAddName(ShiroUtils.getSysUser().getLoginName());
        agentAysinfo.setLocaldate(DateUtils.getDate());
        agentAysinfo.setLocaltime(DateUtils.getOnlyTime());
        return toAjax(agentAysinfoService.insertAgentAysinfo(agentAysinfo));
    }

    /**
     * 修改代理商推送配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        AgentAysinfo agentAysinfo = agentAysinfoService.selectAgentAysinfoById(id);
        mmap.put("agentAysinfo", agentAysinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理商推送配置
     */
    @RequiresPermissions("agentAysinfo:agentAysinfo:edit")
    @Log(title = "代理商推送配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentAysinfo agentAysinfo) {
        return toAjax(agentAysinfoService.updateAgentAysinfo(agentAysinfo));
    }

    /**
     * 删除代理商推送配置
     */
    @RequiresPermissions("agentAysinfo:agentAysinfo:remove")
    @Log(title = "代理商推送配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(agentAysinfoService.deleteAgentAysinfoByIds(ids));
    }
}
